const express = require('express');

const app = express();

app.use(express.json());

let currentUser = {
    name: 'demo',
    age:10,
}

let userList = [
    {
        id:1,
        name:'demo1',
        age:'20',
        hair:'black'
    },
    {
        id:2,
        name:"demo2",
        age:30,
        hair:'red'
    }
]

let products = [
    {
        id:1,
        name:'demo1',
        price:'100$'
    },
    {
        id:2,
        name:"demo2",
        price:"100$"
    }
]

app.get('/current-user', (req, res) => {
    res.json(currentUser);
})
app.get('/user/:id',(req,res)=>{
    const {id} = req.params;
    res.json(userList.find(user=>user.id==id));
})

app.get('/product/:id',(req,res)=>{
    const {id} = req.params;
    res.json(products.find(item=>item.id==id));
})



app.listen(8080,()=>{
    console.log('server is running on port 8080');
})